﻿using ENode.Domain;
using ESTAR.Infrastructure;
using System;
using System.Collections.Generic;
using System.Text;

namespace ESTAR.Domain.Auth
{
    public class UserInfo : AggregateRoot<string>
    {

        /// <summary>
        /// 用户名
        /// </summary>
        public string UserName { get; private set; }

        /// <summary>
        /// 密码
        /// </summary>
        public string Password { get;private set; }


        public UserInfo()
        {
        }
        public UserInfo(string id, string name, string password)
            : base(id)
        {
            Assert.IsNotNullOrWhiteSpace("账号", name);
            Assert.IsNotNullOrWhiteSpace("密码", password);
            if (name.Length > 128)
            {
                throw new Exception("账号长度不能超过128");
            }
            if (password.Length > 128)
            {
                throw new Exception("密码长度不能超过128");
            }
            ApplyEvent(new NewUserInfoRegisteredEvent(name, password));
        }

        private void Handle(NewUserInfoRegisteredEvent evnt)
        {
            UserName = evnt.UserName;
            Password = evnt.Password;
        }
    }
}
